//
//  OnlineTabBarButton.m
//  iBaby365v2
//
//  Created by admin on 14/12/2.
//  Copyright (c) 2014年 suplus. All rights reserved.
//
// 图标的比例
#define SPTabBarButtonImageRatio 0.6
// 按钮的默认文字颜色
#define  SPTabBarButtonTitleColor (iOS7 ? [UIColor blackColor] : [UIColor whiteColor])
// 按钮的选中文字颜色
#define  SPTabBarButtonTitleSelectedColor (iOS7 ? RGBACOLOR(234, 103, 7,1.0) : RGBACOLOR(248, 139, 0,1.0))

#import "OnlineTabBarButton.h"

@implementation OnlineTabBarButton

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        图标居中
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;
//        文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
//        字体大小
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        [self setTitleColor:SPTabBarButtonTitleColor forState:UIControlStateNormal];
        [self setTitleColor:SPTabBarButtonTitleSelectedColor forState:UIControlStateSelected];
        
    }
    return self;
}
/**
 *  只要覆盖了这个方法，按钮就不存在高亮状态
 */
-(void)setHighlighted:(BOOL)highlighted
{
//    [super setHighlighted:<#highlighted#>];
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageW = contentRect.size.width * 0.2;
    CGFloat imageH = contentRect.size.height * SPTabBarButtonImageRatio;
    CGFloat imageX = (self.bounds.size.width-imageW)/2;
    return CGRectMake(imageX, 0, imageW, imageH);
}
//内部文字的frame
-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleY = contentRect.size.height * SPTabBarButtonImageRatio;
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = contentRect.size.height - titleY;
    return CGRectMake(0, titleY, titleW, titleH);
}

@end
